<form id="myform" class="layui-form layui-form-pane" action="" style="margin: 5px">
    <div class="layui-form-item">
        <label class="layui-form-label">编号</label>
        <div class="layui-input-block" >
            <input id="id" lay-filter="test1" type="text" name="number" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input id="title" type="text" name="title" required  lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题描述</label>
        <div class="layui-input-block">
            <input id="titledescription" type="text" name="titledescription" required  lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">回答</label>
        <div class="layui-input-block">
            <input id="answer" type="text" name="answer" required  lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">操作员</label>
        <div class="layui-input-block">
            <input type="text" name="operator" required value="cwjk" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['jquery','baajax','form'], function(){
        var form = layui.form;
        var ajax=layui.baajax;
        var $=layui.jquery;
        getInfo();
        ajax.get("/questionanswer/"+$("#layer_questionanswerId").val(),{},function (data) {
            //if(data.code=='200'){
            //layer.msg('添加成功');
            $("#id").val(data.id);
            $("#title").val(data.title);
            $("#titledescription").val(data.titledescription);
            $("#answer").val(data.answer);
            $("#operator").val(data.operator);
            if(data.userflag===0){
                $("#switch").prop('checked','checked');
            }else{
                $("#switch").removeAttr('checked');
            }
            form.render('checkbox');
            //}
        },function () {
            layer.msg('查询失败');
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            $.ajax({
                type: "POST",
                url: "/questionanswer",
                dataType: "json",
                data: data.field,
                cache: true,
                async: false,
                success: function (data) {
                    if(data.code=='200'){
                        //layer.msg('添加成功');
                        layer.confirm('修改成功,是否继续修改?', {icon: 3, title:'提示'}, function(index){
                            //form.render(null, 'test1');
                            // $("#myform").get(0).reset();
                            // getInfo
                            layer.close(index);
                        },function(index){
                            //do something
                            //alert(index);
                            //table.refresh();
                            layer.closeAll();
                        });
                    }
                    // var ret = data;
                    // succFunc(ret, paras);
                },
                error: function () {
                    layer.msg('失败');
                    // errorFunc();
                }
            })
            return false;
        });

        function getInfo(){
            ajax.get("/questionanswer/"+$("#layer_questionanswerId").val(),{},function (data) {
                //if(data.code=='200'){
                //layer.msg('添加成功');
                $("#id").val(data.id);
                $("#title").val(data.title);
                $("#titledescription").val(data.titledescription);
                $("#answer").val(data.answer);
                $("#operator").val(data.operator);
                if(data.userflag===0){
                    $("#switch").prop('checked','checked');
                }else{
                    $("#switch").removeAttr('checked');
                }
                form.render('checkbox');
                //}
            },function () {
                layer.msg('查询失败');
            });
        }



    });

</script>